package com.ssy.lingxi.settle.accounts.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.contract.api.model.vo.request.ContractPageRequest;
import com.ssy.lingxi.order.api.model.vo.request.OrderBuyerSettlePageVO;
import com.ssy.lingxi.settle.accounts.model.vo.request.*;
import com.ssy.lingxi.settle.accounts.model.vo.response.*;
import com.ssy.lingxi.settle.accounts.service.IApplyAmountService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 平台结算管理-业务请款-采购方
 * @author Houpengfei
 * @date 2021/12/6
 **/
@RestController
@RequestMapping("/settle/accounts/business/apply/amount")
public class ApplyAmountController extends BaseController {

    @Resource
    private IApplyAmountService service;

    /**
     * 生成请款明细项（非物料对账单）
     * @param request 请求类型、和单据信息
     * @return 新增请款明细列表
     */
    @RequestMapping(value = "/generate/save/apply/amount/rows", method = RequestMethod.POST)
    public Wrapper<List<ApplyAmountRowSaveVO>> generateSaveApplyAmountRows(HttpServletRequest request,  @RequestBody ApplyAmountRowGenerateVO queryParameterVO) {
        getSysUser(request);
        return service.generateSaveApplyAmountRows(queryParameterVO);
    }

    /**
     * 核销请款单（非物料对账）列表
     * @param request 请求
     * @param queryParameterVO 查询条件
     * @return 核销请款单（非物料对账）列表
     */
    @RequestMapping(value = "/find/can/apply/amount/ros", method = RequestMethod.POST)
    public Wrapper<PageData<ApplyAmountRowWriteOffRecordSaveVO>> findCanApplyAmountRows(HttpServletRequest request, @Valid @RequestBody CanApplyAmountRowQueryParameterVO queryParameterVO) {
        getSysUser(request);
        return service.findCanApplyAmountRows(queryParameterVO);
    }

    /**
     * 新增请款单-选择待请款单据-查询列表
     * @param request 请求
     * @param queryParameter 查询条件
     * @return 待请款单据
     */
    @RequestMapping(value = "/find/apply/amount/ros/source/orders", method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountOrderVO>> findApplyAmountRowSourceOrders(HttpServletRequest request, @Valid OrderBuyerSettlePageVO queryParameter) {
        return service.findApplyAmountRowSourceOrders(getSysUser(request), queryParameter);
    }

    /**
     * 新增请款单-选择请款合同-查询列表
     * @param request 请求
     * @param queryParameter 查询条件
     * @return 请款合同
     */
    @RequestMapping(value = "/find/apply/amount/ros/source/contracts", method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountContractVO>> findApplyAmountRowSourceContracts(HttpServletRequest request, @Valid ContractPageRequest queryParameter) {
        return service.findApplyAmountRowSourceContracts(getSysUser(request), queryParameter);
    }

    /**
     * 新增请款单
     * @author Saske
     */
    @RequestMapping(value = "/save/apply/amount",method = RequestMethod.POST)
    public Wrapper<Void> save(HttpServletRequest request,@Valid @RequestBody ApplyAmountSaveVO saveVO){
        return service.save(getSysUser(request),saveVO);
    }

    /**
     * 修改请款单
     * @param request 请求
     * @param updateVO 修改请款单
     * @return 修改结果
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Wrapper<Void> update(HttpServletRequest request, @Valid @RequestBody ApplyAmountUpdateVO updateVO) {
        return service.update(getSysUser(request), updateVO);
    }

    /**
     * 删除请款单
     * @param request 请求
     * @param idVO 请款单id
     * @return 删除结果
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Wrapper<Void> delete(HttpServletRequest request, @RequestBody ApplyAmountSubmitVO idVO) {
        return service.delete(getSysUser(request),idVO.getId());
    }

    /**
     * 分页查询请款单列表-付款方为当前登录会员（会员角色为服务消费者）
     * @author Saske
     */
    @RequestMapping(value = "buyer/apply/amount/list",method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountPageVO>> buyerApplyAmountList(HttpServletRequest request, ApplyAmountQueryVO queryVO){
        return service.pageBuyerApplyAmount(getSysUser(request),queryVO);
    }

    /**
     * 分页查询待新增请款单列表-付款方为当前登录会员（会员角色为服务消费者）
     * @author Saske
     */
    @RequestMapping(value = "to/add/apply/amount/list",method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountPageVO>> toAddApplyAmountList(HttpServletRequest request, ApplyAmountQueryVO queryVO){
        return service.pageToAddApplyAmount(getSysUser(request),queryVO);
    }

    /**
     * 查看请款单详情
     * @author Saske
     */
    @RequestMapping(value = "/detail/apply/amount",method = RequestMethod.GET)
    public Wrapper<ApplyAmountDetailVO> getInfo(HttpServletRequest request, @Valid DetailApplyAmountVO detailApplyAmountVO){
        return service.getInfo(getSysUser(request),detailApplyAmountVO);
    }

    /**
     * 查看请款单行明细列表
     * @author Saske
     */
    @RequestMapping(value = "/apply/amount/row/list",method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountRowDetailVO>> fillDetails(HttpServletRequest request, @Valid DetailApplyAmountVO detailApplyAmountVO){
        return service.findDetails(getSysUser(request),detailApplyAmountVO);
    }

    /**
     * 提交请款单
     * @param request Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/submit/apply/amount",method = RequestMethod.POST)
    public Wrapper<Void> submit(HttpServletRequest request , @RequestBody ApplyAmountOperationVO submitVo){
        return service.submit(getSysUser(request),submitVo);
    }

    /**
     * （请款单查询页面）获取前端页面请款单状态下拉框列表
     * @param request Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/item/apply/amount/status",method = RequestMethod.GET)
    public Wrapper<List<DropdownItem>> findStatusList(HttpServletRequest request){
        return service.findStatusList(getSysUser(request));
    }

    /**
     * 查询请款类型列表-排除物料对账单的
     * @param request 请求
     * @return 查询结果
     */
    @RequestMapping(value = "/item/apply/amount/type",method = RequestMethod.GET)
    public Wrapper<List<DropdownItem>> findTypeList(HttpServletRequest request) {
        // step1: 登录校验
        getSysUser(request);
        return service.findTypeList();
    }
}
